'''Alert'''
import my_today_time

from google.appengine.api import mail
from bcuser import get_user_account
from bcuser import BasecampAccount

def content(handler):
    user_list = BasecampAccount.all()

    for user in user_list:
        hours = sum(my_today_time.gettime(get_user_account(user.owner)).values())

        stat = ''
        stat += mail_alert(user.owner, hours)

    return stat
            
def css(handler):
    pass

def mail_alert(user, hours):
    if hours >= 9.0:
        return
        
    message = mail.EmailMessage(sender="lazyM0m3nt@gmail.com",
                                subject="[BasecampReport] Please check your time log")

    message.to = user.email()
    message.body = '''
    You have only %f hours from 9 hours recorded today, did you forget to log your time?
    ''' % hours 

    stat = ''
    try:
        message.send()
        stat += 'Send to %s success.<br />' % user.email()
    except Exception, e:
        stat += 'Send to %s fail. Error: %s<br />' % (user.email(), e)

    return stat
